package com.intelligence.pda.ui.landing.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.intelligence.pda.R;
import com.intelligence.pda.ui.landing.LandigDetailsActivity;
import com.intelligence.pda.ui.landing.model.LandingMatchModel;
import com.intelligence.pda.utils.AppConstants;

import java.util.ArrayList;

/**
 * Created by Administrator
 * on 2017/10/24.
 */

public class LandingMatchAdapter extends RecyclerView.Adapter<LandingMatchAdapter.ViewHolder> {
    public ArrayList<LandingMatchModel.DataBean> datas = null;
    public Context mContext;

    public LandingMatchAdapter(Context context, ArrayList<LandingMatchModel.DataBean> datas) {
        this.datas = datas;
        this.mContext = context;
    }

    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_landingmatch_library, viewGroup, false);
        return new ViewHolder(view);
    }

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {
        viewHolder.tv_takeTime.setText(datas.get(position).getArriveTime());
            viewHolder.tv_City.setText("发车城市:" + datas.get(position).getInitCity());
            viewHolder.tv_License.setText(datas.get(position).getVehicleNo());
            viewHolder.tv_orderNum.setText(datas.get(position).getOrderNum() + "笔");
            viewHolder.tv_scan.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, LandigDetailsActivity.class);
                    intent.putExtra(AppConstants.BATCH_NO, datas.get(position).getBatchNo());
                    mContext.startActivity(intent);
                }
            });


    }

    //获取数据的数量
    @Override
    public int getItemCount() {
        return datas.size();
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView tv_takeTime;
        public TextView tv_City;
        public TextView tv_License;
        public TextView tv_orderNum;
        public TextView tv_scan;

        public ViewHolder(View view) {
            super(view);
            tv_takeTime = (TextView) view.findViewById(R.id.tv_takeTime);
            tv_City = (TextView) view.findViewById(R.id.tv_City);
            tv_License = (TextView) view.findViewById(R.id.tv_License);
            tv_orderNum = (TextView) view.findViewById(R.id.tv_orderNum);
            tv_scan = (TextView) view.findViewById(R.id.tv_scan);
        }
    }
}